<?php

namespace platform\controllers;

use platform\core\BaseController;
use platform\interfaces\MainInterface;
use platform\models\LoginModel;
use platform\models\MainModel;
use cm;

class MainController extends BaseController implements MainInterface
{
    /*
    * 首页
    */
    function actionIndex()
    {
        $this->layout = false;
        $data = (new MainModel())->actionIndex();
        Cm::$cache->clear();
        return Cm::$res->render($this, "main", $data, '首页');
    }

    /*
    * 登录
    */
    function actionLogin()
    {
        $this->layout = false;
        $data = (new LoginModel())->actionLogin();
        
        return Cm::$res->render($this, 'login', $data);
    }

    /*
    * 退出
    */
    function actionLogout()
    {
        Cm::$app->log->authlog(2,"","退出");
        Cm::$app->user->logout();
        Cm::$res->redirect(['main/login']);
    }

    /*
    * 错误页
    */
    function actionError(){
        echo isset($_GET['msg'])?$_GET['msg']:'未知错误';
        //exit();
    }
}